extends layout

block headContent
	title RPC Browser #{(method ? (" - " + method) : false)}

	style.
		pre {
			white-space: pre-wrap;       /* Since CSS 2.1 */
			word-wrap: break-word;       /* Internet Explorer 5.5+ */
		}

block content
	h1.h3.mb-0 RPC Browser
	hr

	if (gethelp)
		div.row
			div.col-md-9
				if (methodhelp)
					div.card.shadow-sm.mb-3
						div.card-body
							div.clearfix
								div.float-left
									h3.h6.mb-0
										a.text-body(href=`./rpc-browser?method=${method}`)
											span.font-weight-bold #{method}
										span  Command

								div.float-right
									a(href=("https://bitcoin.org/en/developer-reference#" + method)) Docs for #{method} &raquo;
							hr

							ul.nav.nav-tabs.mb-3
								li.nav-item
									a.nav-link.active(data-toggle="tab", href="#tab-execute", role="tab") Execute
								li.nav-item
									a.nav-link(data-toggle="tab", href="#tab-help-content", role="tab") Help Content

								if (methodhelp.args && methodhelp.args.length > 0)
									li.nav-item
										a.nav-link(data-toggle="tab", href="#tab-parsed-args", role="tab") Arguments Details

							div.tab-content
								div.tab-pane.active(id="tab-execute", role="tabpanel")
									if (methodResult)
										div.mt-4
											div.mb-2
												h3.h6.mt-3 Result

											pre.border.mb-3
												code.json.bg-light(data-lang="json") #{JSON.stringify(methodResult, null, 4)}

										hr

									form(method="get")
										input(type="hidden", name="_csrf", value=csrfToken)
										input(type="hidden", name="method", value=method)

										div.mb-3
											h6 Arguments

										if (false)
											pre
												code.json #{JSON.stringify(argValues, null, 4)}
										
										div.ml-3
											each argX, index in methodhelp.args
												div.form-group
													label(for=("arg_" + argX.name))
														div
															span.text-monospace.font-weight-bold #{argX.name}
															span.text-monospace : 
																span  #{argX.properties.join(", ")}
														if (argX.description)
															span.text-muted Description: #{argX.description}
														if (false && argX.detailsLines && argX.detailsLines.length > 0)
															- var detailsLines = "";
															each detailsLine in argX.detailsLines
																- detailsLines = (detailsLines + "<br/>" + detailsLine);
															i.fas.fa-info-circle(data-toggle="tooltip", title=detailsLines)
																


													- var valX = false;
													if (argValues != null)
														if (argValues[index] != null)
															if (("" + argValues[index]) != "NaN")
																- valX = JSON.stringify(argValues[index]);
																if (valX.substring(0, 1) == "\"")
																	- valX = valX.substring(1);
																if (valX.substring(valX.length - 1, valX.length) == "\"")
																	- valX = valX.substring(0, valX.length - 1);

													if (method == "verifymessage" && argX.name == "message")
														- var newline = String.fromCharCode(13, 10);
														textarea.form-control(id=("arg_" + argX.name), name=("args[" + index + "]"), placeholder=argX.name, rows="8") #{(valX ? valX.split('\\n').join(newline) : "")}
														
													else
														input.form-control(id=("arg_" + argX.name), type="text", name=("args[" + index + "]"), placeholder=argX.name, value=(valX ? valX : ""))

											if (!methodhelp.args || methodhelp.args.length == 0)
												span.text-muted None

										hr

										input.btn.btn-primary.px-3(type="submit", name="execute", value="Execute")

								div.tab-pane(id="tab-help-content", role="tabpanel")
									pre.border
										code.json.bg-light(data-lang="txt") #{methodhelp.string}

								if (methodhelp.args && methodhelp.args.length > 0)
									div.tab-pane(id="tab-parsed-args", role="tabpanel")
										pre.border
											code.json.bg-light(data-lang="json") #{JSON.stringify(methodhelp.args, null, 4)}

					
							

				else
					:markdown-it
						Browse RPC commands from the list. The list is built from the results of the `help` command and organized into sections accordingly.

			div.col-md-3
				each section, sectionIndex in gethelp
					div.card.shadow-sm.mb-3
						div.card-body
							h4.h6.mb-0 #{section.name}
								small  (#{section.methods.length})
							hr
							
							ol(style="padding-left: 30px;")
								each methodX, methodIndex in section.methods
									li
										a.text-monospace(href=("./rpc-browser?method=" + methodX.name), style=(methodX.name == method ? "font-weight: bold; font-style: italic;" : false)) #{methodX.name}

